package com.study.SpringBootLesson4.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;

/**
 * @author 赵超
 * @Description springboot 注解注册servlet学习
 * @create 2017-11-29 10:36
 **/
@WebServlet(
        name = "myServlet",
        urlPatterns = "/myServer",
        initParams = {
                @WebInitParam(name = "myKey1", value = "myValue1"),
                @WebInitParam(name = "myKey2", value = "myValue2"),
        }
)//标记为servlet
public class MyServlet extends HttpServlet {

    private String value;

    public void init(ServletConfig servletConfig) {
        value = servletConfig.getInitParameter("myKey1");
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {

        Writer writer = response.getWriter();

        ServletContext servletContext = request.getServletContext();
        servletContext.log("server doGet");

        writer.write("<html><body>Hello," + value + ",Fuck!</body></html>");

    }
}
